<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html 
     PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
  <title>Module: ActiveSupport::Rescuable</title>
  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  <meta http-equiv="Content-Script-Type" content="text/javascript" />
  <link rel="stylesheet" href="../.././rdoc-style.css" type="text/css" media="screen" />
  <script type="text/javascript">
  // <![CDATA[

  function popupCode( url ) {
    window.open(url, "Code", "resizable=yes,scrollbars=yes,toolbar=no,status=no,height=150,width=400")
  }

  function toggleCode( id ) {
    if ( document.getElementById )
      elem = document.getElementById( id );
    else if ( document.all )
      elem = eval( "document.all." + id );
    else
      return false;

    elemStyle = elem.style;
    
    if ( elemStyle.display != "block" ) {
      elemStyle.display = "block"
    } else {
      elemStyle.display = "none"
    }

    return true;
  }
  
  // Make codeblocks hidden by default
  document.writeln( "<style type=\"text/css\">div.method-source-code { display: none }</style>" )
  
  // ]]>
  </script>

</head>
<body>



    <div id="classHeader">
        <table class="header-table">
        <tr class="top-aligned-row">
          <td><strong>Module</strong></td>
          <td class="class-name-in-header">ActiveSupport::Rescuable</td>
        </tr>
        <tr class="top-aligned-row">
            <td><strong>In:</strong></td>
            <td>
                <a href="../../files/vendor/rails/activesupport/lib/active_support/rescuable_rb.html">
                vendor/rails/activesupport/lib/active_support/rescuable.rb
                </a>
        <br />
            </td>
        </tr>

        </table>
    </div>
  <!-- banner header -->

  <div id="bodyContent">



  <div id="contextContent">

    <div id="description">
      <p>
<a href="Rescuable.html">Rescuable</a> module adds support for easier
exception handling.
</p>

    </div>


   </div>

    <div id="method-list">
      <h3 class="section-bar">Methods</h3>

      <div class="name-list">
      <a href="#M000268">handler_for_rescue</a>&nbsp;&nbsp;
      <a href="#M000267">rescue_with_handler</a>&nbsp;&nbsp;
      </div>
    </div>

  </div>


    <!-- if includes -->

    <div id="section">

    <div id="class-list">
      <h3 class="section-bar">Classes and Modules</h3>

      Module <a href="Rescuable/ClassMethods.html" class="link">ActiveSupport::Rescuable::ClassMethods</a><br />

    </div>




      


    <!-- if method_list -->
    <div id="methods">
      <h3 class="section-bar">Public Instance methods</h3>

      <div id="method-M000268" class="method-detail">
        <a name="M000268"></a>

        <div class="method-heading">
          <a href="#M000268" class="method-signature">
          <span class="method-name">handler_for_rescue</span><span class="method-args">(exception)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000268-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000268-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/rails/activesupport/lib/active_support/rescuable.rb, line 78</span>
 78:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">handler_for_rescue</span>(<span class="ruby-identifier">exception</span>)
 79:       <span class="ruby-comment cmt"># We go from right to left because pairs are pushed onto rescue_handlers</span>
 80:       <span class="ruby-comment cmt"># as rescue_from declarations are found.</span>
 81:       <span class="ruby-identifier">_</span>, <span class="ruby-identifier">rescuer</span> = <span class="ruby-constant">Array</span>(<span class="ruby-identifier">rescue_handlers</span>).<span class="ruby-identifier">reverse</span>.<span class="ruby-identifier">detect</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">klass_name</span>, <span class="ruby-identifier">handler</span><span class="ruby-operator">|</span>
 82:         <span class="ruby-comment cmt"># The purpose of allowing strings in rescue_from is to support the</span>
 83:         <span class="ruby-comment cmt"># declaration of handler associations for exception classes whose</span>
 84:         <span class="ruby-comment cmt"># definition is yet unknown.</span>
 85:         <span class="ruby-comment cmt">#</span>
 86:         <span class="ruby-comment cmt"># Since this loop needs the constants it would be inconsistent to</span>
 87:         <span class="ruby-comment cmt"># assume they should exist at this point. An early raised exception</span>
 88:         <span class="ruby-comment cmt"># could trigger some other handler and the array could include</span>
 89:         <span class="ruby-comment cmt"># precisely a string whose corresponding constant has not yet been</span>
 90:         <span class="ruby-comment cmt"># seen. This is why we are tolerant to unknown constants.</span>
 91:         <span class="ruby-comment cmt">#</span>
 92:         <span class="ruby-comment cmt"># Note that this tolerance only matters if the exception was given as</span>
 93:         <span class="ruby-comment cmt"># a string, otherwise a NameError will be raised by the interpreter</span>
 94:         <span class="ruby-comment cmt"># itself when rescue_from CONSTANT is executed.</span>
 95:         <span class="ruby-identifier">klass</span> = <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">class</span>.<span class="ruby-identifier">const_get</span>(<span class="ruby-identifier">klass_name</span>) <span class="ruby-keyword kw">rescue</span> <span class="ruby-keyword kw">nil</span>
 96:         <span class="ruby-identifier">klass</span> <span class="ruby-operator">||=</span> <span class="ruby-identifier">klass_name</span>.<span class="ruby-identifier">constantize</span> <span class="ruby-keyword kw">rescue</span> <span class="ruby-keyword kw">nil</span>
 97:         <span class="ruby-identifier">exception</span>.<span class="ruby-identifier">is_a?</span>(<span class="ruby-identifier">klass</span>) <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">klass</span>
 98:       <span class="ruby-keyword kw">end</span>
 99: 
100:       <span class="ruby-keyword kw">case</span> <span class="ruby-identifier">rescuer</span>
101:       <span class="ruby-keyword kw">when</span> <span class="ruby-constant">Symbol</span>
102:         <span class="ruby-identifier">method</span>(<span class="ruby-identifier">rescuer</span>)
103:       <span class="ruby-keyword kw">when</span> <span class="ruby-constant">Proc</span>
104:         <span class="ruby-identifier">rescuer</span>.<span class="ruby-identifier">bind</span>(<span class="ruby-keyword kw">self</span>)
105:       <span class="ruby-keyword kw">end</span>
106:     <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000267" class="method-detail">
        <a name="M000267"></a>

        <div class="method-heading">
          <a href="#M000267" class="method-signature">
          <span class="method-name">rescue_with_handler</span><span class="method-args">(exception)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Tries to rescue the exception by looking up and calling a registered
handler.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000267-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000267-source">
<pre>
    <span class="ruby-comment cmt"># File vendor/rails/activesupport/lib/active_support/rescuable.rb, line 71</span>
71:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">rescue_with_handler</span>(<span class="ruby-identifier">exception</span>)
72:       <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">handler</span> = <span class="ruby-identifier">handler_for_rescue</span>(<span class="ruby-identifier">exception</span>)
73:         <span class="ruby-identifier">handler</span>.<span class="ruby-identifier">arity</span> <span class="ruby-operator">!=</span> <span class="ruby-value">0</span> <span class="ruby-operator">?</span> <span class="ruby-identifier">handler</span>.<span class="ruby-identifier">call</span>(<span class="ruby-identifier">exception</span>) <span class="ruby-operator">:</span> <span class="ruby-identifier">handler</span>.<span class="ruby-identifier">call</span>
74:         <span class="ruby-keyword kw">true</span> <span class="ruby-comment cmt"># don't rely on the return value of the handler</span>
75:       <span class="ruby-keyword kw">end</span>
76:     <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>


    </div>


  </div>


<div id="validator-badges">
  <p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
</div>

</body>
</html>